package com.wushijia.java8.concurrent;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class Executors4 {

  public static void main(String[] args) throws ExecutionException, InterruptedException {
    long begin = System.currentTimeMillis();
    List<String> stringList = new ArrayList<>();
    ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(10);
    for (int i = 0; i < 10; i++) {
      stringList.add((String) scheduledThreadPool.submit(new Task1()).get());
    }
    long end = System.currentTimeMillis();
    System.out.println("spend time:" + (end - begin) / 1000);
  }

}

class Task1 implements Callable {

  @Override
  public Object call() throws Exception {
    Thread.sleep(1000);
    return "null";
  }
}
